package demo01;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//测试类
public class Application {

    //创建一个列表用来存放菜品
    static List<Dish> dishList = new ArrayList<>();
    static List<Dish> personDish = new ArrayList<>();

    public static void main(String[] args) {

        initDish();//静态方法，可以直接调用


        //判断用户输入的数字
        while (true){
            showMenu();//展示主页

            Scanner scanner = new Scanner(System.in);
            int a = scanner.nextInt();
            switch (a){
                case 1:
                    while (true){
                        System.out.println("请点菜：");
                        showDish();//展示菜单
                        System.out.println("---按0返回---");
                        int id = scanner.nextInt();
                        if (id == 0)
                            break;
                        if (id >= 1 || id <= dishList.size()){
                            Dish dish = dishList.get(id - 1);
                            personDish.add(dish);
                            System.out.println("您点了"+dish.name);
                        }
                        else
                            System.out.println("请重新输入");
                    }
                    break;
                case 2:
                    showPersonDish();
                    break;
                case 3:
                    personCost();
                    break;
                case 0:
                    break;
                default:
                    System.out.println("请重新输入");
            }
        }

    }

    //初始化菜品的函数
    //静态方法，只能在本类中调用
    public static void initDish(){
        dishList.add(new Dish(1,"油闷大虾",60));
        dishList.add(new Dish(2,"手撕鸡",30));
        dishList.add(new Dish(3,"番茄炒蛋",15));
        dishList.add(new Dish(4,"地三鲜",20));
        dishList.add(new Dish(5,"家常凉菜",21));
    }

    //展示主页
    public static void showMenu(){
        System.out.println("=============");
        System.out.println("\t欢迎\t\t");
        System.out.println("菜单\t\t\t1");
        System.out.println("已点菜品\t\t2");
        System.out.println("结账\t\t\t3");
        System.out.println("=============");
    }

    //展示菜单
    public static void showDish(){
        for (int i = 0; i < dishList.size(); i++) {
            Dish dish= dishList.get(i);
            System.out.println(dish.id+"\t"+dish.name+"\t"+dish.price);
        }
    }

    //已点菜品
    public static void showPersonDish(){
        System.out.println("---您已点菜品---");
        for (int i = 0; i < personDish.size(); i++) {
            Dish dish= personDish.get(i);
            System.out.println(dish.id+"\t"+dish.name+"\t"+dish.price);
        }
        System.out.println("---按0返回---");
    }

    //结账
    public static void personCost(){
        double cost = 0;
        for (int i = 0; i < personDish.size(); i++) {
            Dish dish= personDish.get(i);
            cost += dish.price;
        }
        System.out.println("您一共消费了："+cost);
    }
}
